package com.zhonghui.modlules.order.controller;

import com.zhonghui.common.bean.LocalUser;
import com.zhonghui.common.eshopDomain.ShopUser;
import com.zhonghui.common.eshopUtil.ApiResult;
import com.zhonghui.modlules.order.eshopService.StoreOrderService;
import com.zhonghui.modlules.order.param.DoOrderParam;
import com.zhonghui.modlules.order.param.ProductReplyParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @_(@Autowired))
@Api(value = "订单模块",tags = "订单模块")
public class StoreOrderController {

    private final StoreOrderService storeOrderService;

    @ApiOperation(value = "订单收货",notes = "订单收货")
    @PostMapping("/order/take")
    public ApiResult<Boolean> orderTake(@Validated @RequestBody DoOrderParam doOrderParam){
        Long uid = LocalUser.getUser().getUid();
        storeOrderService.takeOrder(doOrderParam.getUni(),uid);
        return ApiResult.ok();
    }

    @ApiOperation(value = "订单删除",notes = "订单删除")
    @PostMapping("/order/del")
    public ApiResult<Boolean> cartDel(@Validated @RequestBody DoOrderParam doOrderParam){
        Long uid = LocalUser.getUser().getUid();
        storeOrderService.removeOrder(doOrderParam.getUni(),uid);
        return ApiResult.ok();
    }

    @ApiOperation(value = "订单评价",notes = "订单评价")
    @PostMapping("/order/comment")
    public ApiResult<Boolean> orderComment(@Validated @RequestBody ProductReplyParam replyParam){
        ShopUser shopUser = LocalUser.getUser();
        storeOrderService.orderComment(shopUser,replyParam.getUnique(),replyParam.getComment(),
                replyParam.getPics(),replyParam.getProductScore(),replyParam.getServiceScore());
        return ApiResult.ok();
    }

    @ApiOperation(value = "订单退款理由",notes = "订单退款理由")
    @GetMapping("/order/refund/reason")
    public ApiResult<Object> orderRefund(){
        ArrayList<String> list = new ArrayList<>();
        list.add("收货地址填错了");
        list.add("与描述的不符");
        list.add("信息填错了，重新拍");
        list.add("收到的商品损坏了");
        list.add("未按预定时间发货");
        list.add("其他原因");

        return ApiResult.ok(list);
    }
}
